package com.mera.tektronix.csviewer.domain



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Employee)
class EmployeeTests {

	Employee employee
	
	@Before
	void setUp() {
		mockForConstraintsTests(Employee)
		Project project = new Project(name: "Project", email: "project@mera.ru", phone: "278-88-88#0011")
		employee = new Employee(name:"Employee", birthDate: new Date("1989/1/9"), email: "emp_1@mera.ru", hiredDate:new Date("2012/1/1"), position:"Position", phone:"278-88-88#0001", project: project)
	}
	
	void testConstraintsEmailEmail() {
		employee.email = 'badEmail'
		assertFalse employee.validate()
		assertEquals 'email', employee.errors['email']

		employee.email = 'mera@mera.ru'
		assertTrue employee.validate()
		assertNull employee.errors['email']
	}
	
	void testConstraintsPhoneMatches() {
		employee.phone = "235678"
		assertFalse employee.validate()
		assertEquals 'matches', employee.errors['phone']
		
		employee.phone = "278-88-65"
		assertTrue employee.validate()
		assertNull employee.errors['phone']
	}
	
	void testConstraintsHiredDateNullable() {
		employee.hiredDate = null
		assertFalse employee.validate()
		assertEquals 'nullable', employee.errors['hiredDate']

		employee.hiredDate = new Date("1980/11/11");
		assertTrue employee.validate()
		assertNull employee.errors['hiredDate']
	}
	
	void testConstraintsPositionBlank() {
		employee.position = ""
		assertFalse employee.validate()
		assertEquals 'blank', employee.errors['position']

		employee.position = "Position"
		assertTrue employee.validate()
		assertNull employee.errors['position']
	}
}
